// 表单校验规则由 schema2code 生成，不建议直接修改校验规则，而建议通过 schema2code 生成, 详情: https://uniapp.dcloud.net.cn/uniCloud/schema


const validator = {
  "nickname": {
    "rules": [
      {
        "format": "string"
      }
    ],
    "title": "昵称",
    "label": "昵称"
  },
  "name": {
    "rules": [
      {
        "format": "string"
      }
    ],
    "title": "姓名",
    "label": "姓名"
  },
  "phone": {
    "rules": [
      {
        "format": "string"
      },
      {
        "pattern": "^\\+?[0-9-]{3,20}$"
      }
    ],
    "title": "手机号码",
    "label": "手机号码"
  },
  "identity": {
    "rules": [
      {
        "format": "string"
      }
    ],
    "title": "身份证号码",
    "label": "身份证号码"
  },
  "birthday": {
    "rules": [
      {
        "format": "string"
      }
    ],
    "title": "出生年月日",
    "label": "出生年月日"
  },
  "school": {
    "rules": [
      {
        "format": "string"
      }
    ],
    "title": "毕业院校",
    "label": "毕业院校"
  },
  "degree": {
    "rules": [
      {
        "format": "string"
      }
    ],
    "title": "学历",
    "label": "学历"
  },
  "major": {
    "rules": [
      {
        "format": "string"
      }
    ],
    "title": "专业",
    "label": "专业"
  },
  "job_title": {
    "rules": [
      {
        "format": "string"
      }
    ],
    "title": "职称",
    "label": "职称"
  },
  "workplace": {
    "rules": [
      {
        "format": "string"
      }
    ],
    "title": "工作单位",
    "label": "工作单位"
  },
  "home_address": {
    "rules": [
      {
        "format": "string"
      }
    ],
    "title": "家庭住址",
    "label": "家庭住址"
  },
  "training": {
    "rules": [
      {
        "format": "string"
      }
    ],
    "title": "参加过哪些培训",
    "label": "参加过哪些培训"
  },
  "degree_provement": {
    "rules": [
      {
        "format": "array"
      }
    ],
    "title": "学历证明",
    "label": "学历证明"
  },
  "job_title_provement": {
    "rules": [
      {
        "format": "array"
      }
    ],
    "title": "职称证明",
    "label": "职称证明"
  },
  "training_provement": {
    "rules": [
      {
        "format": "array"
      }
    ],
    "title": "培训证书",
    "label": "培训证书"
  },
  "resume": {
    "rules": [
      {
        "format": "string"
      }
    ],
    "title": "简历",
    "label": "简历"
  },
  "skilled": {
    "rules": [
      {
        "format": "array"
      },
      {
        "range": [
          {
            "text": "青少年特发性脊柱侧弯康复",
            "value": "1"
          },
          {
            "text": "各类不良体态矫正",
            "value": "2"
          },
          {
            "text": "产后康复",
            "value": "3"
          }
        ]
      }
    ],
    "title": "擅长领域",
    "label": "擅长领域"
  },
  "talent": {
    "rules": [
      {
        "format": "array"
      },
      {
        "range": [
          {
            "text": "体态评估",
            "value": "65f9ada021821b6d2b3816ce"
          },
          {
            "text": "脖子前倾/富贵包",
            "value": "65f9adae9755e32830ebc469"
          },
          {
            "text": "溜肩",
            "value": "65f9adb5a09a9b12d71ff0c0"
          },
          {
            "text": "圆肩驼背",
            "value": "65f9adbb09664cbba09a40a4"
          },
          {
            "text": "高低肩",
            "value": "65f9adc121821b6d2b381c2c"
          },
          {
            "text": "肋骨外翻",
            "value": "65f9adc655b3372a1fa5ffdf"
          },
          {
            "text": "脊柱侧弯",
            "value": "65f9adcca09a9b12d71ff4c2"
          },
          {
            "text": "骨盆前倾",
            "value": "65f9add3f08210b07d29dbab"
          },
          {
            "text": "假胯宽",
            "value": "65f9addae0ec199b181e2f4a"
          },
          {
            "text": "产后骨盆修复",
            "value": "65f9ade2213929f86662c351"
          },
          {
            "text": "SPS训练团课",
            "value": "65f9ade9189f861ff7aba6b0"
          },
          {
            "text": "体态塑形体验",
            "value": "65f9adf109664cbba09a4926"
          },
          {
            "text": "局部舒缓-头颈肩",
            "value": "65f9adfa189f861ff7abaf9c"
          },
          {
            "text": "局部舒缓-腰背腿",
            "value": "65f9ae019755e32830ebd285"
          },
          {
            "text": "扁平足",
            "value": "65f9ae0799c6244dcfd658d2"
          }
        ]
      }
    ],
    "title": "评估后胜任领域",
    "label": "评估后胜任领域"
  },
  "reason": {
    "rules": [
      {
        "format": "string"
      }
    ],
    "title": "审核原因",
    "label": "审核原因"
  },
  "status": {
    "rules": [
      {
        "format": "int"
      },
      {
        "range": [
          {
            "text": "禁用",
            "value": 0
          },
          {
            "text": "审核中",
            "value": 1
          },
          {
            "text": "审核通过",
            "value": 2
          },
          {
            "text": "审核拒绝",
            "value": 3
          }
        ]
      }
    ],
    "title": "审核状态",
    "defaultValue": 1,
    "label": "审核状态"
  }
}

const enumConverter = {
  "skilled_valuetotext": [
    {
      "text": "青少年特发性脊柱侧弯康复",
      "value": "1"
    },
    {
      "text": "各类不良体态矫正",
      "value": "2"
    },
    {
      "text": "产后康复",
      "value": "3"
    }
  ],
  "talent_valuetotext": [
    {
      "text": "体态评估",
      "value": "65f9ada021821b6d2b3816ce"
    },
    {
      "text": "脖子前倾/富贵包",
      "value": "65f9adae9755e32830ebc469"
    },
    {
      "text": "溜肩",
      "value": "65f9adb5a09a9b12d71ff0c0"
    },
    {
      "text": "圆肩驼背",
      "value": "65f9adbb09664cbba09a40a4"
    },
    {
      "text": "高低肩",
      "value": "65f9adc121821b6d2b381c2c"
    },
    {
      "text": "肋骨外翻",
      "value": "65f9adc655b3372a1fa5ffdf"
    },
    {
      "text": "脊柱侧弯",
      "value": "65f9adcca09a9b12d71ff4c2"
    },
    {
      "text": "骨盆前倾",
      "value": "65f9add3f08210b07d29dbab"
    },
    {
      "text": "假胯宽",
      "value": "65f9addae0ec199b181e2f4a"
    },
    {
      "text": "产后骨盆修复",
      "value": "65f9ade2213929f86662c351"
    },
    {
      "text": "SPS训练团课",
      "value": "65f9ade9189f861ff7aba6b0"
    },
    {
      "text": "体态塑形体验",
      "value": "65f9adf109664cbba09a4926"
    },
    {
      "text": "局部舒缓-头颈肩",
      "value": "65f9adfa189f861ff7abaf9c"
    },
    {
      "text": "局部舒缓-腰背腿",
      "value": "65f9ae019755e32830ebd285"
    },
    {
      "text": "扁平足",
      "value": "65f9ae0799c6244dcfd658d2"
    }
  ],
  "status_valuetotext": {
    "0": "禁用",
    "1": "审核中",
    "2": "审核通过",
    "3": "审核拒绝"
  }
}

function filterToWhere(filter, command) {
  let where = {}
  for (let field in filter) {
    let { type, value } = filter[field]
    switch (type) {
      case "search":
        if (typeof value === 'string' && value.length) {
          where[field] = new RegExp(value)
        }
        break;
      case "select":
        if (value.length) {
          let selectValue = []
          for (let s of value) {
            selectValue.push(command.eq(s))
          }
          where[field] = command.or(selectValue)
        }
        break;
      case "range":
        if (value.length) {
          let gt = value[0]
          let lt = value[1]
          where[field] = command.and([command.gte(gt), command.lte(lt)])
        }
        break;
      case "date":
        if (value.length) {
          let [s, e] = value
          let startDate = new Date(s)
          let endDate = new Date(e)
          where[field] = command.and([command.gte(startDate), command.lte(endDate)])
        }
        break;
      case "timestamp":
        if (value.length) {
          let [startDate, endDate] = value
          where[field] = command.and([command.gte(startDate), command.lte(endDate)])
        }
        break;
    }
  }
  return where
}

export { validator, enumConverter, filterToWhere }
